package cn.hubujyjs.mooc.controller;

import cn.hubujyjs.mooc.common.Result;
import cn.hubujyjs.mooc.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/file")
@Api(tags = "文件接口")
public class FileController {
    @Autowired
    private OssService ossService;
    @ApiOperation("上传视频")
    @PostMapping("/uploadVideo")
    public Result<Map<String,String>> uploadVideo(@RequestPart("file") MultipartFile file){
        String s = ossService.uploadVideo(file);
        Map<String, String> map = new HashMap<>();
        map.put("videoSrc",s);
        //阿里云oss获取视频文件第一帧
        map.put("imgSrc",s+"?x-oss-process=video/snapshot,t_1000,m_fast");
        return Result.success(map);

    }
}
